/**
 * Project: TacticaPescaditos
 * File: ReturnToHome.java
 */
package org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.fsm.state;

import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.GoalKeeper;
import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.messages.Telegram;

/**
 * @author Carlos Alberto
 * class: ReturnToHome
 */
public class ReturnToHome implements State<GoalKeeper> {
	
	/**
	 * 
	 */
	private ReturnToHome() {
	}

	public static final State<GoalKeeper> instance = new ReturnToHome();

	public void enter(GoalKeeper keeper) {
		keeper.getSteering().seekOn();
	}

	public void execute(GoalKeeper keeper) {
		
		keeper.getSteering().setTarget(keeper.getHomePosition());
		
		if (keeper.isAtTarget() || !keeper.getTactica().isControlling()){
			keeper.getStateMachine().changeState(TendGoal.instance);
		}
		
		
		
	}

	public void exit(GoalKeeper keeper) {
		keeper.getSteering().seekOff();
		
	}

	public boolean onMessage(GoalKeeper keeper, Telegram telegram) {
		return false;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "ReturnToHome";
	}

}
